import { Request } from 'express';

export function generateClientId(req: Request): string {
  const fingerprint = [
    req.ip, // IP地址
    req.headers['user-agent'], // 浏览器UA
    req.headers['accept-language'], // 语言
  ].join('|');
  console.log('fingerprint::', fingerprint);
  // 简单哈希
  let hash = 0;
  for (let i = 0; i < fingerprint.length; i++) {
    const char = fingerprint.charCodeAt(i);
    hash = (hash << 5) - hash + char;
    hash = hash & hash;
  }
  return `client:${hash}`;
}
